﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChanSharp
{
    public class AttachedFile
    {
        public string URL;
        public string ChanFilename;
        public string OriginalFilename;
        public string MD5;
        public string Filesize;
        public bool IsSpoilered;

        public int EstimatedLength
        {
            get
            {
                int sizelength = Filesize.IndexOf(' ');
                float numerical = float.Parse(Filesize.Substring(0, sizelength));
                if (Filesize.EndsWith("MB"))
                {
                    return (int)(numerical * 1000000);
                }
                if (Filesize.EndsWith("KB"))
                {
                    return (int)(numerical * 1000);
                }
                if (Filesize.EndsWith("B"))
                {
                    return (int)numerical;
                }
                throw new Exception("Bad filesize string.");
            }
        }

        public AttachedFile(string URL, string ChanFilename, string OriginalFilename, string MD5, string Filesize, bool IsSpoilered)
        {
            this.URL = URL;
            this.ChanFilename = ChanFilename;
            this.OriginalFilename = OriginalFilename;
            this.MD5 = MD5;
            this.Filesize = Filesize;
            this.IsSpoilered = IsSpoilered;
        }

    }
}
